<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8>
    </head>
    <body>
    	
        <script type="text/javascript">
            /**
             * 就是对 class类中getter的简单应用，没啥了
             * 有getter必然有getter，这里也演示了setter的用法
             */
            class Rectangle {
                // 补全代码
                constructor(height,width){
                    this.height = height;
                    this.width = width;
                }
                //Getter
                get area(){
                    return this.height * this.width;
                }

                //Setter
                set dimensions({height,width}){
                    this.height = height;
                    this.width = width;
                }
            }
            const rect = new Rectangle();//这里咱故意不传惨，便于演示下面的setter
            rect.dimensions={height: 12, width: 12}
            console.log(rect.area);
        </script>
    </body>
</html>